import React from 'react'
import Son from './Son'
import { useState } from 'react'
import { Button } from 'antd';
export default function Father() {
    const [num,setNum] = useState(133)
    const [info,setInfo]= useState({
        age:20,
        name:'张三'
    })
    const changeInfo = () => {
      console.log(123);
      
      setNum(c => c +1)
      setInfo(c => {
        console.log(c);
        c.age ++
        c.name = '李四'
        return c
      })
    }
    // 父掉子
    const sonRef = React.useRef(null)
    const changeSon = () => {
      if(sonRef.current) {
        sonRef.current.changeName()
        sonRef.current.logFunc()
      }
    }
  return (
    <div>
        <span >{info.name}</span>
        <span>{info.age}</span>
        <Button type="primary" onClick={changeInfo}>改变信息</Button>
        <Button type="primary" onClick={changeSon}>掉子组件方法</Button>
        <div>
            <Son num={num} ref={sonRef} changeInfo={changeInfo} />
        </div>
    </div>
  )
}
